<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of tblCustomers
 *
 * @author chema_000
 */
class Admin_Models_tblCustomers extends Libs_Model{
    protected $queryUnit;
    public function __construct()
    {
        parent::__construct();
        $this->queryUnit = new Libs_QueryUnit();
    }

    private $id;
    private $email;
    private $phone;
    private $address;
    private $firstname;
    private $lastname;
    private $point;
    
    public function getId() {
        return $this->id;
    }

    public function getEmail() {
        return $this->email;
    }

    public function getPhone() {
        return $this->phone;
    }

    public function getAddress() {
        return $this->address;
    }

    public function getFirstname() {
        return $this->firstname;
    }

    public function getLastname() {
        return $this->lastname;
    }

    public function getPoint() {
        return $this->point;
    }
    
    public function setId($id) {
        $this->id = $id;
    }

    public function setEmail($email) {
        $this->email = $email;
    }

    public function setPhone($phone) {
        $this->phone = $phone;
    }

    public function setAddress($address) {
        $this->address = $address;
    }

    public function setFirstname($firstname) {
        $this->firstname = $firstname;
    }

    public function setLastname($lastname) {
        $this->lastname = $lastname;
    }

    public function setPoint($point) {
        $this->point = $point;
    }

        
    public function setCustomerValue($row, $isKey=FALSE)
    {
        $cus = new Admin_Models_tblCustomers();
        if($isKey){
            $cus->setId($row['id']);
        }
        $cus->setPhone($row['phone']);
        $cus->setEmail($row['email']);
        $cus->setAddress($row['address']);
        $cus->setFirstName($row['firstname']);
        $cus->setLastName($row['lastname']);
        $cus->setPoint($row['point']);
        return $cus;
    }
    
    public function getSearchCustomers($keyword)
    {
        $listAllCus = array();
        $execute = $this->queryUnit->getSelect('tbl_customers',"email LIKE '%$keyword%' ");
        if (mysql_num_rows($execute) > 0) {
            while ($row = mysql_fetch_assoc($execute)) {
                $cus = $this->setCustomerValue($row);
                $listAllCus[] = $cus;
            }
        }
        return $listAllCus;
    }    
    public function getAllCustomer(){
         $listAllCus= array();
         $execute= $this->queryUnit->getSelect('tbl_customers');
         if(mysql_num_rows($execute)>0){
             while ($row= mysql_fetch_assoc($execute)){
                 $listAllCus[]=$this->setCustomerValue($row,true);
             }
         }
         return $listAllCus;
    }
    public function deleteCustomer($cus_id){
        $execute= $this->queryUnit->getDelete('tbl_customers', "email='$cus_id'");
        if($execute){
            return TRUE;
        }
        return FALSE;
    }
}
